#include <algorithm>
#include <cstdio>
#include <map>
#include <vector>

const int N = 3e4 + 5, M = 1e5 + 5;
int n, m, cnt, dfn[N], dep[N], fa[N], son[N], top[N], siz[N], ans[N];

struct Query {
  int u, v;
  bool opt;
  Query(int u, int v, bool opt) : u(u), v(v), opt(opt) {}
};

std::vector<Query> q;
std::map<int, int> map[N];

int e_cnt, heads[N];

struct Edge {
  int v, nxt;
  bool uavi;
} e[M << 1];

inline void add(int u, int v) {
  e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], heads[u] = e_cnt;
  map[u][v] = e_cnt;
}

struct Node {
  int sum;
  bool tag;
} tr[N << 2];

inline void pushup(int x) { tr[x].sum = tr[x << 1].sum + tr[x << 1 | 1].sum; }

inline void pushdown(int x) {
  static int ls, rs;
  if (tr[x].tag) {
    ls = x << 1, rs = x << 1 | 1;
    tr[ls].sum = tr[rs].sum = 0;
    tr[ls].tag = tr[rs].tag = true;
    tr[x].tag = false;
  }
}

void modify(int x, int l, int r, int L, int R) {
  if (L <= l && r <= R) { return tr[x].tag = true, tr[x].sum = 0, void(); }
  int mid = (l + r) >> 1;
  pushdown(x);
  if (L <= mid) modify(x << 1, l, mid, L, R);
  if (mid < R) modify(x << 1 | 1, mid + 1, r, L, R);
  pushup(x);
}

int query(int x, int l, int r, int L, int R) {
  if (L <= l && r <= R) return tr[x].sum;
  int mid = (l + r) >> 1, res = 0;
  pushdown(x);
  if (L <= mid) res += query(x << 1, l, mid, L, R);
  if (mid < R) res += query(x << 1 | 1, mid + 1, r, L, R);
  return res;
}

void dfs1(int x) {
  siz[x] = 1;
  for (int i = heads[x], v; i; i = e[i].nxt) {
    if (!e[i].uavi && (v = e[i].v) != fa[x] && !dep[v]) {
      fa[v] = x, dep[v] = dep[x] + 1;
      dfs1(v);
      siz[x] += siz[v];
      if (siz[son[x]] < siz[v]) son[x] = v;
    }
  }
}

void dfs2(int x) {
  dfn[x] = ++cnt;
  if (son[x]) top[son[x]] = top[x], dfs2(son[x]);
  for (int i = heads[x], v; i; i = e[i].nxt) {
    if (!e[i].uavi && (v = e[i].v) != fa[x] && v != son[x] && fa[v] == x) { top[v] = v, dfs2(v); }
  }
}

inline void modifychain(int x, int y) {
  while (top[x] != top[y]) {
    if (dep[top[x]] < dep[top[y]]) std::swap(x, y);
    modify(1, 1, n, dfn[top[x]], dfn[x]);
    x = fa[top[x]];
  }
  if (dep[x] < dep[y]) std::swap(x, y);
  if (dep[x] != dep[y]) modify(1, 1, n, dfn[y] + 1, dfn[x]);
}

inline int querychain(int x, int y) {
  int res = 0;
  while (top[x] != top[y]) {
    if (dep[top[x]] < dep[top[y]]) std::swap(x, y);
    res += query(1, 1, n, dfn[top[x]], dfn[x]);
    x = fa[top[x]];
  }
  if (dep[x] < dep[y]) std::swap(x, y);
  res -= query(1, 1, n, dfn[y], dfn[y]);
  return res += query(1, 1, n, dfn[y], dfn[x]);
}

void build(int x, int l, int r) {
  if (l == r) return tr[x].sum = 1, void();
  int mid = (l + r) >> 1;
  build(x << 1, l, mid);
  build(x << 1 | 1, mid + 1, r);
  pushup(x);
}

void solve(int x) {
  for (int i = heads[x], v; i; i = e[i].nxt) {
    if (!e[i].uavi) {
      if (fa[v = e[i].v] == x) solve(v);
      if (dep[v] != dep[x] + 1 && v != fa[x]) modifychain(v, x);
    }
  }
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("P1772 [ZJOI2006]物流运输.in", "r", stdin);
  freopen("P1772 [ZJOI2006]物流运输.out", "w", stdout);
#endif
#endif

  scanf("%d%d", &n, &m);
  int u, v, opt;
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &u, &v);
    add(u, v), add(v, u);
  }
  while (true) {
    scanf("%d", &opt);
    if (opt == -1) break;
    scanf("%d%d", &u, &v);
    q.emplace_back(u, v, opt);
    if (!opt) e[map[u][v]].uavi = true, e[map[v][u]].uavi = true;
  }
  fa[1] = 1, top[1] = 1, dep[1] = 1;
  dfs1(1), dfs2(1);
  build(1, 1, n);
  solve(1);
  for (int i = q.size() - 1; ~i; --i) {
    if (q[i].opt) ans[i] = querychain(q[i].u, q[i].v);
    else
      modifychain(q[i].u, q[i].v);
  }
  for (auto i = q.begin(); i != q.end(); ++i)
    if (i->opt) printf("%d\n", ans[i - q.begin()]);
  return 0;
}